<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/laypage.css">
<script src="js/vue/vue.min.js"></script>
<script src="js/jquery/jquery.min.js"></script>
<script src="js/laypage/laypage.js" charset="UTF-8"></script>
<script src="js/layer/layer.js" charset="UTF-8"></script>
<body>
<div id="app" class="container">
    <form class="form-inline bg-danger" role="form">
        查询条件
        <div class="form-group">
            <label class="sr-only" for="username">用户名称</label>
            <input type="text" class="form-control" id="username" placeholder="用户名称">
        </div>
        <div class="form-group">
            <label class="sr-only" for="userage">用户年龄</label>
            <input type="text" class="form-control" id="userage" placeholder="用户年龄">
        </div>
        <button type="button" id="findUser" class="btn btn-success">查询用户</button>
        <button type="button" id="addUserBtn" class="btn btn-danger">增加用户</button>
    </form>

    <div class="table-responsive">
        <table class="table">
            <thead>
            <tr class="success">
                <td>序号</td>
                <td>用户</td>
                <td>年龄</td>
                <td>角色</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            <tr class="active" v-for="(item,index) in result">
                <td>{{index+1}}</td>
                <td>{{item.name}}</td>
                <td>{{item.age}}</td>
                <td>{{item.rolename}}</td>
                <td><a href="">编辑</a></td>
            </tr>
            </tbody>
        </table>
        <div id="pagenav"></div>
    </div>

</div>
</body>
</html>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            result: []
        }
    });

    //查询数据
    var getUserPageList = function (curr) {
        $.ajax({
            type: 'GET',
            dataType: 'json',
            url: '/user/getcond',
            data: {
                pageNum: curr || 1,
                pageSize: 3,
                name: $("#username").val()
            },
            success: function (msg) {
                app.result = msg.result;
                laypage({
                    cont: 'pagenav', //容器。值支持id名、原生dom对象，jquery对象,
                    pages: msg.totalPage, //总页数
                    first: '首页',
                    last: '尾页',
                    skin:'#007799',
                    curr: curr || 1, //当前页
                    jump: function (obj, first) { //触发分页后的回调
                        if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                            getUserPageList(obj.curr);
                        }
                    }
                });
            }
        });
    }

    getUserPageList();

</script>
